package com.z.jdbc_demo;

import java.sql.*;

public class JdbcExample {
    public static void main(String[] args) throws ClassNotFoundException, SQLException{
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/zk?user=root&password=123456");
        PreparedStatement preparedStatement = connection.prepareStatement("select * from t_student");
        ResultSet resultSet = preparedStatement.executeQuery();
        System.out.println("ID"+"\t"+"学生姓名"+"\t"+"分数"+"\t\t"+"年龄");
        while(resultSet.next()){
            int stuID = resultSet.getInt("stu_id");
            String stuName = resultSet.getString("stu_name");
            double stuScore = resultSet.getDouble("stu_score");
            int stu_age = resultSet.getInt("stu_age");
            System.out.println(stuID+"\t"+stuName+"\t\t"+stuScore+"\t"+stu_age);
        }
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
